﻿

<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>设置我的资料</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
	<link rel="stylesheet" href="~/lib/layuiadmin/layui/css/layui.css" media="all">
	<link rel="stylesheet" href="~/lib/layuiadmin/style/admin.css" media="all">
</head>
<body>

	<div class="layui-fluid">
		<div class="layui-row layui-col-space15">
			<div class="layui-col-md12">
				<div class="layui-card">
					<div class="layui-card-header">设置我的资料</div>
					<div class="layui-card-body" pad15>
						<div class="layui-form" lay-filter="edit">
							<div class="layui-form-item">
								<label class="layui-form-label">用户名</label>
								<div class="layui-input-inline">
									<input type="hidden" name="id" value="@ViewBag.User.Id" />
									<input type="text" name="name" lay-verify="required" value="@ViewBag.User.Name" autocomplete="off" placeholder="请输入用户名" class="layui-input">
								</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">手机</label>
								<div class="layui-input-inline">
									<input type="text" name="tel" value="@ViewBag.User.Tel" lay-verify="phone" autocomplete="off" placeholder="请输入手机号" class="layui-input">
								</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">邮箱</label>
								<div class="layui-input-inline">
									<input type="text" name="email" value="@ViewBag.User.Email" lay-verify="email" autocomplete="off" placeholder="请输入邮箱" class="layui-input">
								</div>
							</div>
							<div class="layui-form-item layui-form-text">
								<label class="layui-form-label">备注</label>
								<div class="layui-input-block">
									<textarea type="text" name="bak" placeholder="请输入备注" class="layui-textarea">@ViewBag.User.Bak</textarea>
								</div>
							</div>
							<div class="layui-form-item">
								<div class="layui-input-block">
									<button type="submit" class="layui-btn" lay-submit lay-filter="modify">确认修改</button>
									<button type="submit" class="layui-btn layui-btn-primary" lay-submit lay-filter="reset">重新填写</button>
								</div>
							</div>
						</div>

					</div>
				</div>
			</div>
		</div>
	</div>

	<script src="~/lib/layuiadmin/layui/layui.js"></script>
	<script>
		layui.use(['layer', 'form'], function () {
			var $ = layui.$
				, form = layui.form
				, layer = layui.layer

			//表单事件
			form.on('submit(modify)', function (obj) {
				//console.log(obj.field);
				$.post({
					url: '/api/user/editinfo'
					, type: "post"
					, data: JSON.stringify(obj.field)
					, contentType: "application/json"
					, success: function (res) {
						if (res.code == 200) {
							window.location.reload();
							layer.msg("修改成功");
						} else {
							layer.msg(res.msg);
						}
					}
				});
			});

			//重置
			form.on('submit(reset)', function (obj) {
				form.val("edit", {
					"name": "@Html.Raw(ViewBag.User.Name)",
					"tel": "@Html.Raw(ViewBag.User.Tel)",
					"email": "@Html.Raw(ViewBag.User.Email)",
					"bak": "@Html.Raw(ViewBag.User.Bak)"
				});
				form.render();
			});
		});
	</script>
</body>
</html>